package utils

import (
	"github.com/dgrijalva/jwt-go"
	"time"
)

var (
	SignKey []byte =[]byte("secret")
)

type MyCustomClaims struct{
	UserId string `json:"userId"`
	jwt.StandardClaims
}

//簽名生成token串
func Sign(userId string) (string,error) {

	// Create the Claims
	claims := MyCustomClaims{
		userId,
		jwt.StandardClaims{
			ExpiresAt: time.Now().Unix()+7 * 24 * 36 * 36 * 1000,
			Issuer:    "kevin",
		},
	}
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
	ss, err := token.SignedString(SignKey)
	if err!=nil{
		return "",err
	}
	return ss,nil

}
